import { DeptParams, DeptListItem, UploadRoleResult, ApplyTask } from './model/systemModel';

import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios';

enum Api {
  AddDeptPageList = '/admin/dept/add',
  UpdateDeptPageList = '/admin/dept/update',
  DelDeptPageList = '/admin/dept/del',
  DeptPageList = '/admin/dept/tree',
  GetDeptPageList = '/admin/dept',
  ExportDept = '/admin/dept/export',
  TempDept = '/admin/sys-file/local/file/dept.xlsx',
  ImportDept = '/admin/dept/import',
  GetAllCaliber = '/jd/task/getAllCaliber',
  GetAllOperate = '/jd/task/getAllOperate',
  GetApplyList = '/jd/task/applyList',
  AddTaskList = '/jd/task/addTask',
  GetCaliberByApplyId = '/jd/task/getCaliberByApplyId',
}
export const getDeptTreeByPage = (params?: DeptParams) =>
  defHttp.get<any>({ url: Api.DeptPageList, params });

export const addDeptApi = (params: DeptListItem) =>
  defHttp.post<any>({ url: Api.AddDeptPageList, params });

export const updateDeptApi = (params: DeptListItem) =>
  defHttp.post<any>({ url: Api.UpdateDeptPageList, params });

export const deleteDeptApi = (id: string) =>
  defHttp.post<any>({ url: Api.DelDeptPageList + '/' + id });
export const getDeptInfoApi = (id: string) =>
  defHttp.get<DeptListItem>({ url: Api.GetDeptPageList + '/' + id });

export const exportDeptApi = () =>
  defHttp.get<any>(
    { url: Api.ExportDept, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export const tempDeptApi = () =>
  defHttp.get<any>(
    { url: Api.TempDept, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export function uploadDeptApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadRoleResult[]>(
    {
      url: Api.ImportDept,
      onUploadProgress,
    },
    params,
  );
}

export const GetAllCaliber = (params) => {
  return defHttp.get<any>({ url: Api.GetAllCaliber, params });
};

export const GetAllOperate = (params) => {
  return defHttp.get<any>({ url: Api.GetAllOperate, params });
};

export const GetApplyList = (params: {
  id: string;
  current?: string | number;
  size?: string | number;
}) => {
  return defHttp.get<any>({
    url: Api.GetApplyList + '/' + params.id,
    params: {
      current: params.current,
      size: params.size,
    },
  });
};

export const AddTaskList = (params: ApplyTask) => {
  return defHttp.post<any>({ url: Api.AddTaskList, params });
};

export const GetCaliberByApplyId = (id: string) =>
  defHttp.get<any>({ url: Api.GetCaliberByApplyId + '/' + id });
